package com.cenwangkeji.zhihuimuye.ui.fragment;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.cenwangkeji.zhihuimuye.R;
import com.cenwangkeji.zhihuimuye.model.bean.StatisticsBean;
import com.cenwangkeji.zhihuimuye.ui.activity.BirthDetailActivity;
import com.cenwangkeji.zhihuimuye.ui.activity.CowStatisticsDetailActivity;
import com.cenwangkeji.zhihuimuye.ui.activity.HeatDetailActivity;
import com.cenwangkeji.zhihuimuye.ui.activity.IllnessDetailActivity;
import com.cenwangkeji.zhihuimuye.ui.activity.PregnancyDetailActivity;
import com.cenwangkeji.zhihuimuye.ui.activity.SellDetailActivity;
import com.cenwangkeji.zhihuimuye.ui.adapter.StatisticsAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lws.basic.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @松 on 2019/10/9 11:00
 */
public class StatisticsFragment extends BaseFragment implements BaseQuickAdapter.OnItemClickListener {
    @BindView(R.id.rv)
    RecyclerView mRv;
    Unbinder unbinder;
    private List<StatisticsBean> mList = new ArrayList<>();

    @Override
    public int setLayoutId() {
        return R.layout.fragment_statistics;
    }


    @Override
    protected void initView(View view) {
        super.initView(view);
        unbinder = ButterKnife.bind(this, view);
    }

    @Override
    protected void initData() {
        super.initData();
        initRecyclerView();
    }

    //初始化 界面
    private void initRecyclerView() {
        mList = new ArrayList<>();
        mList.add(new StatisticsBean(R.mipmap.ic_cow, "牛只统计"));
        mList.add(new StatisticsBean(R.mipmap.ic_heat, "发情统计"));
        mList.add(new StatisticsBean(R.mipmap.ic_pregnancy, "孕期统计"));
        mList.add(new StatisticsBean(R.mipmap.ic_birth, "产子统计"));
        mList.add(new StatisticsBean(R.mipmap.ic_illness, "病情统计"));
        mList.add(new StatisticsBean(R.mipmap.ic_sell, "出栏统计"));
        mRv.setLayoutManager(new GridLayoutManager(getContext(), 3));
        StatisticsAdapter adapter = new StatisticsAdapter(mList);
        //adapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
        adapter.setOnItemClickListener(this);
        mRv.setAdapter(adapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (mList.get(position).getIcon()){
                    case R.mipmap.ic_cow:
                        startActivity(new Intent(getActivity(),CowStatisticsDetailActivity.class));
                        break;
                    case R.mipmap.ic_heat:
                        startActivity(new Intent(getActivity(),HeatDetailActivity.class));
                        break;
                    case R.mipmap.ic_pregnancy:
                        startActivity(new Intent(getActivity(),PregnancyDetailActivity.class));
                        break;
                    case R.mipmap.ic_birth:
                        startActivity(new Intent(getActivity(),BirthDetailActivity.class));
                        break;
                    case R.mipmap.ic_illness:
                        startActivity(new Intent(getActivity(),IllnessDetailActivity.class));
                        break;
                    case R.mipmap.ic_sell:
                        startActivity(new Intent(getActivity(),SellDetailActivity.class));
                        break;

                }
    }
}
